/*
 * @Description: 托盘功能
 * @Date: 2024-09-30 14:09:29
 * @FilePath: \demod:\12electron\electron-vite-template\src\main\tray.ts
 */
import { BrowserWindow, Menu, Tray } from 'electron';
import path from 'path';

const createTray = (win: BrowserWindow) => {
  // 苹果的系统托盘图标要求是黑白色的，win系统则可以是彩色的
  const tray = new Tray(
    path.resolve(__dirname, process.platform == 'darwin' ? '../../resources/fish.png' : '../../resources/fish.png'),
  );

  // 定义托盘的菜单
  const contextMenu = Menu.buildFromTemplate([
    { label: '退出', role: 'quit' },
    {
      label: '功能一',
      click: () => {
        console.log('功能一');
      },
    },
    {
      label: '功能二',
      click: () => {
        console.log('功能二');
      },
    },
  ]);
  // 设置托盘悬浮提示
  tray.setToolTip('华康医疗');
  // 设置托盘菜单
  tray.setContextMenu(contextMenu);
  // 点击托盘图标显示应用
  tray.on('click', () => {
    // 显示主窗口
    win.show();
  });
};

export default createTray;
